Code
### USING GTSUMMARY ###
require(gtsummary)
## note on require -- does the same as library() but will continue executing submitted code if package does not exist; not really useful in this case, but can be useful if its within an Rscript or function where you still want the code to run
### try using gtsummary --
reset_gtsummary_theme()
# theme_gtsummary_journal(journal = "jama")
theme_gtsummary_compact()
dput(names(tab1))c("Name", "Team", "GS", "G", "IP", "W", "L", "QS", "SV", "HLD",
"H", "ER", "HR", "SO", "BB", "K.9", "BB.9", "K.BB", "HR.9", "AVG",
"WHIP", "BABIP", "LOB.", "ERA", "FIP", "ADP", "division", "POS"
)
Code
vars_tab1 <- c("Team", "IP", "W", "L", "SV", "K.9", "BB.9", "K.BB", "ERA", "WHIP")
tab1 %>%
dplyr::select(vars_tab1) %>%
gtsummary::tbl_summary(by=Team,
type = list(c("IP", "W", "L", "SV", "K.9", "BB.9", "K.BB", "ERA", "WHIP") ~ "continuous"),
# statistic = list(c("ConnectivityZscore") ~ "{median} [{p25}, {p75}]"
# ),
missing_text = "Missing",
label = list(IP ~ "Innings Pitched",
W ~ "Wins",
L ~ "Losses",
SV ~ "Saves",
K.9 ~ "Strikeouts per 9 innings",
BB.9 ~ "Walks per 9 innings",
K.BB ~ "Strikeouts per walk",
ERA ~ "Earned Run Average",
WHIP ~ "Walks + Hits per inning pitched"
)
) %>%
add_stat_label() %>%
modify_spanning_header(all_stat_cols() ~ "**Team**") %>%
add_difference(everything() ~ "smd") %>%
modify_column_hide(columns=ci)| Characteristic | Team | Difference1 | |
|---|---|---|---|
| LAD, N = 12 | SFG, N = 6 | ||
| Innings Pitched, Median (IQR) | 112 (91, 123) | 86 (66, 129) | 0.07 |
| Wins, Median (IQR) | 8 (6, 10) | 6 (4, 7) | 0.43 |
| Losses, Median (IQR) | 5 (4, 6) | 4 (4, 6) | -0.13 |
| Saves, Median (IQR) | 0 (0, 1) | 1 (0, 2) | -0.29 |
| Strikeouts per 9 innings, Median (IQR) | 9.29 (8.72, 10.16) | 9.38 (7.84, 11.14) | 0.00 |
| Walks per 9 innings, Median (IQR) | 2.90 (2.52, 3.29) | 3.18 (2.28, 3.90) | -0.20 |
| Strikeouts per walk, Median (IQR) | 3.24 (2.67, 3.66) | 3.09 (2.71, 3.41) | 0.24 |
| Earned Run Average, Median (IQR) | 3.72 (3.57, 4.38) | 3.90 (3.71, 3.97) | 0.22 |
| Walks + Hits per inning pitched, Median (IQR) | 1.17 (1.15, 1.30) | 1.27 (1.24, 1.33) | -0.81 |
| 1 Standardized Mean Difference | |||